package cn.tannn.cat.file.server.entity.convert;

import cn.tannn.cat.file.sdk.enums.StorageMaster;
import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;

/**
 * 配置主从 jpa枚举存储转换
 *
 * @author <a href="https://tannn.cn/">tan</a>
 * @date 2024/3/7 13:35
 */
@Converter(autoApply=true)
public class StorageMasterConvert implements AttributeConverter<StorageMaster,Integer> {

    /**
     * 存储的数据
     */
    @Override
    public Integer convertToDatabaseColumn(StorageMaster attribute) {
        return attribute.getType();
    }

    /**
     * 查询转换为枚举
     */
    @Override
    public StorageMaster convertToEntityAttribute(Integer dbData) {
        return StorageMaster.fromValue(dbData);
    }
}
